/**
 * Created by Administrator on 2015/5/5.
 */
var globalApp = null;
var judge = function(operate, arg1, arg2){
    switch (operate){
        case 'equals': return arg1 === arg2;
        case 'lessThan': return arg1 < arg2;
        case 'greaterThan': return arg1 > arg2;
    }
};
module.exports = {
    dbUrl: process.env.DBURL ,
    //dbUrl: 'mongodb://localhost/xyzone' ,
   // dbUrl: 'mongodb://2F0N6mg3:8eG5Yntje161@mongo-2-1.jae.jd.com:27017/xz19921015_mongo_285txdt3' ,
    globalApp: globalApp,
    initglobalApp: function(app){
        this.globalApp = app;
    },
    registerHelper: function(hbs){//注册handlebars的Helper函数
        hbs.registerHelper('truncate', function (content, linkPath, link) {
            content = content + '<hr/><a href="' + linkPath + link + '">查看全文</a>';
            return new hbs.SafeString(content);
        });
        //等于，大于，小于 判断函数，传入两个比较的参数
        'equals,lessThan,greaterThan'.replace(/(\w+)/g, function(method){
            hbs.registerHelper(method, function(arg1, arg2, options){
                return judge(method, arg1, arg2) ? options.fn(this) : options.inverse(this);
            });
        });

    },
    setError: function(errInfo, code){
        module.exports.err = {
            err: errInfo,
            code: code
        };
    }
}